# Build recipe for libassuan
#
# Copyright 2016, 2017 Mateus P. Rodrigues <mprodrigues@dragora.org>.
#
# This recipe is free software, under the terms of the Apache License 2.0

program=libassuan
version=2.4.3
release=1

description="
Libassuan is a small library implementing the so-called Assuan
protocol. This protocol is used for IPC between most newer GnuPG
components. Both, server and client side functions are provided.

In an ideal world, Assuan is irrelevant. Assuan's primary use is to
allow a client to interact with a non-persistent server. Using Assuan,
this is accomplished by forking a subprocess and communicating with it
via, for example, a pipe or unix domain socket. This method is neither
elegant nor efficient especially when there is a lot of data spread
across several transactions: not only is there a penalty for an
increased number of context switches, but also a significant amount of
data is memcpy-ed from the client to a file descriptor and from the
file descriptor to the server. Despite these and other disadvantages,
this type of client/server communication can be useful: the client is
completely separate from the server; they are in different address
spaces. This is especially important in situations where the server
must have a known degree of reliability and data must be protected: as
the Assuan protocol is well defined and clients cannot corrupt the
servers' address space, auditing become much easier.

Assuan was developed for use by the GNU Privacy Guard, GnuPG, to
prevent potentially buggy clients from unwittingly corrupting
sensitive transactions or compromising data such as a secret
key. Assuan permits the servers, which do the actual work,
e.g. encryption and decryption of data using a secret key, to be
developed independently of the user interfaces, e.g. mail clients and
other encryption front ends. Like a shared library, the interface is
well defined and any number of front ends can use it; however, unlike
a shared library, the client cannot see or touch the server's data. As
with any modular system, Assuan helps keep the servers small and
understandable, and helps to make code more understandable and less
error prone.

Assuan is not, however, limited to use with GnuPG servers and clients:
it was design to be flexible enough to meet the demands of almost any
transaction based environment with non-persistent servers.
"

homepage=https://www.gnupg.org/related_software/libassuan/index.en.html
license="GPLv2, LGPLv2"

tarname=${program}-${version}.tar.bz2

# Remote source(s)
fetch=https://www.gnupg.org/ftp/gcrypt/libassuan/$tarname

# Source documentation
docs="AUTHORS COPYING* INSTALL NEWS README* THANKS TODO VERSION"
docsdir="${docdir}/${program}-${version}"

build() {
    unpack "${tardir}/$tarname"

    cd "$srcdir"

    ./configure CFLAGS="$QICFLAGS" LDFLAGS="$QILDFLAGS" \
    $configure_args \
    --libdir=/usr/lib${libSuffix} \
    --mandir=$mandir \
    --docdir=$docdir \
    --build="$(cc -dumpmachine)"

    make -j${jobs}
    make -j${jobs} install DESTDIR="$destdir"

    # Compress and link man pages (if needed)
    if [ -d "${destdir}/$mandir" ] ; then
	(
            cd "${destdir}/$mandir"
	    find . -type f -exec lzip -9 '{}' +
	    find . -type l | while read -r file
	    do
		ln -sf "$(readlink -- "$file").lz" "${file}.lz"
		rm -- "$file"
	    done
	)
    fi

    # Copy documentation
    mkdir -p "${destdir}${docsdir}"

    for file in $docs ; do
            cp -p $file "${destdir}${docsdir}"
	        done
}
